<template>
  <div>
    <el-row :gutter="15">
      <el-col :span="8">
        <el-card>
          <!--          <v-chart :options="drawChart" ref="chart" id="main" style="height: 400px; width: 400px"></v-chart>-->
          <!--          <div ref="chart" style="height: 500px; width: 450px"> </div>-->
          <!--          <div id="main" style="width: 600px; height: 400px"></div>-->

        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card>
          <div id="chart" style="height: 500px; width: 450px"></div>
        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card>
          <div id="chart" style="height: 500px; width: 450px"></div>
        </el-card>
      </el-col>
    </el-row >
    <el-row :gutter="15" style="height: 50%;margin-top: 15px">
      <el-col :span="8">
        <el-card>

        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card>

        </el-card>
      </el-col>
      <el-col :span="8">
        <el-card>

        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
//import echarts from 'echarts';
import * as echarts from 'echarts';
import ECharts from 'vue-echarts'
import { mapState } from 'vuex'
export default {
  name: "Index",
  components: {
    //'v-chart': ECharts
    // ECharts
  },
  data() {
    return {
      chartInstance: null,
      // 示例数据
      data: [
        {value: 335, name: '直接访问'},
        {value: 310, name: '邮件营销'},
        {value: 234, name: '联盟广告'},
        {value: 135, name: '视频广告'},
        {value: 1048, name: '搜索引擎'}
      ],
      // 版本号
      version: "3.8.7"
    }
  },

  mounted() {
    this.$nextTick(() => {
      this.chartInstance = echarts.init(document.getElementById('chart'));
      this.drawChart();
    });
    // this.chartInstance = echarts.init(document.getElementById('chart'));
    // this.drawChart();
    //this.drawChart();
  },
  methods: {
    drawChart() {
      const option = {
        title: {
          text: '访问来源',
          subtext: '纯属虚构',
          x: 'center'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          left: 'left',
          data: this.data.map(item => item.name)
        },
        series: [{
          name: '访问来源',
          type: 'pie',
          radius: '55%',
          center: ['50%', '60%'],
          data: this.data,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }]
      };

      this.chartInstance.setOption(option);
    }
    // drawChart() {
    //   // 基于准备好的dom，初始化echarts实例  这个和上面的main对应
    //   let myChart = this.$echarts.init(document.getElementById("main"));
    //   // 指定图表的配置项和数据
    //   let option = {
    //     title: {
    //       text: "ECharts 入门示例",
    //     },
    //     tooltip: {},
    //     legend: {
    //       data: ["销量"],
    //     },
    //     xAxis: {
    //       data: ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
    //     },
    //     yAxis: {},
    //     series: [
    //       {
    //         name: "销量",
    //         type: "bar",
    //         data: [5, 20, 36, 10, 10, 20],
    //       },
    //     ],
    //   };
    //   // 使用刚指定的配置项和数据显示图表。
    //   myChart.setOption(option);
    // },


  },
  // computed: {
  //   ...mapState(['yourData']) // 从Vuex中获取数据，替换'yourData'为实际的数据状态名
  // },
  // watch: {
  //   yourData(newData, oldData) {
  //     if (newData !== oldData) {
  //       this.chartOptions.series[0].data = newData // 将数据更新到图表配置中
  //       this.$refs.chart.updateOptions(this.chartOptions)
  //     }
  //   }
  // }
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }

  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }

  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}
</style>

